using System;
using System.Collections.Generic;
using System.Text;

namespace Dominio
{
    public class Bug
    {
        private int id;
        private String description;
        private String so;
        private String soVersion;
        private String tipo;
        private Release release;
        private Tester tester;
        private String status;
        private double price;
        private IList<Question> questionList;

        //Empty contructor used by hibernate
        protected Bug()
        {}
        public Bug(String description, String so, String version, String type, Release release, Tester tester)
        {
            this.description = description;
            this.so = so;
            this.SoVersion = version;
            this.tipo = type;
            this.release = release;
            this.tester = tester;
            this.status = "Pending";
            calculatePrice();
        }

        public Bug(int id, String description, String so, String soVersion, String type, Release release, String bugstatus, Tester tester)
        {
            this.Id = id;
            this.Description = description;
            this.So = so;
            this.SoVersion = soVersion;
            this.Tipo = type;
            this.Release = release;
            this.Status = bugstatus;
            this.Tester = tester;
        }

        public virtual bool isEditable(object user)
        {
            User usuario = (User)user;
            return (this.status.Equals(BugStatusEnum.Pending.ToString()) && usuario.Role.isTM(usuario)) || (this.status.Equals(BugStatusEnum.NotApproved.ToString()) && usuario.Role.isTester(usuario));
        }

        public virtual void calculatePrice()
        {
               if (this.Tipo.Equals(BugTypeEnum.Gui.ToString())){
                   this.price = 10 + (this.release.Maturity * 10) / 100;
               }
               else if (this.Tipo.Equals(BugTypeEnum.Funcional.ToString()))
               {
                   this.price = 20 + (this.release.Maturity * 20) / 100;
               }
               else if (this.Tipo.Equals(BugTypeEnum.Tecnico.ToString()))
               {
                   this.price = 30 + (this.release.Maturity * 30) / 100;
               }
        }
       

        #region Properties

        public virtual Release Release
        {
            get { return release; }
            set { release = value; }
        }
        public virtual IList<Question> QuestionList
        {
            get { return questionList; }
            set { questionList = value; }
        }
        public virtual Tester Tester
        {
            get { return tester; }
            set { tester = value; }
        }
        public virtual String Tipo
        {
            get { return tipo; }
            set { tipo = value; }
        }
        public virtual String Status
        {
            get { return status; }
            set { status = value; }
        }

        public virtual String SoVersion
        {
            get { return soVersion; }
            set { soVersion = value; }
        }

        public virtual double Price
        {
            get { return price; }
            set { price = value; }
        }

        public virtual String So
        {
            get { return so; }
            set { so = value; }
        }


        public virtual String Description
        {
            get { return description; }
            set { description = value; }
        }

        public virtual int Id
        {
            get { return id; }
            set { id = value; }
        } 
        #endregion

    }
}
